package com.xuanyuan.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProxy;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionSupport;
import com.xuanyuan.service.SendMessageService;
import com.xuanyuan.util.GlobalParameter;
import com.xuanyuan.util.PageInfo;
import com.xuanyuan.util.SendMsg_webchinese;
import com.xuanyuan.vo.DepartmentsVo;


@Component("sendMessageAction")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@RemoteProxy(name = "sendMessageAction")
public class SendMessageAction extends ActionSupport{
	SendMessageService sendMessageService;
	
	  @RemoteMethod
      public Map<String, Object> loadUsers(PageInfo pageInfo){
    	 List<DepartmentsVo> list = sendMessageService.getUsersVo(pageInfo);
    	 Map<String, Object> map = new HashMap<String,Object>();
    	 map.put("users", list);
    	 map.put("pageInfo", pageInfo);
    	 return map;
      }
      
	  @RemoteMethod
	  public Map<String, Object> loadUsersByDepartment(String departmentName, PageInfo pageInfo){
		  List<DepartmentsVo> list = sendMessageService.getUsersVoByDepartment(departmentName, pageInfo);
		  Map<String, Object> map = new HashMap<String, Object>();
		  map.put("users", list);
		  map.put("pageInfo", pageInfo);
		  return map;
	  }
	  
	  @RemoteMethod
	  public Map<String, Object> sendMessage(String phoneNumbers,String messageContent)throws Exception{
		  String[] phones = phoneNumbers.split(",");
		  for(int i=0; i<phones.length; i++){
			  System.out.println(phones[i]);
		  }
		  return SendMsg_webchinese.sendMessage(GlobalParameter.USERNAME, GlobalParameter.PASSWORD, phones, messageContent);
	  }
	  
	  @RemoteMethod
	  public Map<String,Object> loadUserByDepartmentId(Integer id, PageInfo pageInfo){
		 List<DepartmentsVo> dVo = sendMessageService.getDapartmentsById(id, pageInfo);
		 Map<String, Object> map = new HashMap<String,Object>();
		 map.put("users", dVo);
		 map.put("pageInfo", pageInfo);
		  return map;
	  }
	  
    @Resource
	public void setSendMessageService(SendMessageService sendMessageService) {
		this.sendMessageService = sendMessageService;
	}
      
     
}
